package com.taoyibao.hongcanting.ui.home.delegate;

import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.taoyibao.hongcanting.R;
import com.taoyibao.hongcanting.base.delegate.BackToolbarDelegate;
import com.taoyibao.hongcanting.widget.HorizontalLineTextView;
import com.taoyibao.hongcanting.model.DishModel;
import com.taoyibao.hongcanting.model.SupplementModel;
import com.taoyibao.hongcanting.ui.home.views.ItemChooseAddArea;
import com.taoyibao.hongcanting.utils.CodeUtils;
import com.taoyibao.hongcanting.utils.GlideUtil;
import com.taoyibao.hongcanting.utils.LogUtils;
import com.taoyibao.hongcanting.utils.ToastUtils;

/**
 * @author TangAnna
 * @description: 添加菜品之前的选择
 * @date :${DATA} 13:54
 */
public class ChooseAddDelegate extends BackToolbarDelegate {
    private static final String TAG = "ChooseAddDelegate";
    private TextView mTvName;
    private TextView mTvDiscountPrice;
    private HorizontalLineTextView mTvDishPrice;
    private ImageView mIvPic;
    private ItemChooseAddArea mItemTaste;
    private ItemChooseAddArea mItemMakeUp;

    @Override
    public int getRootLayoutId() {
        return R.layout.activity_choose_add;
    }

    @Override
    public void initWidget() {
        super.initWidget();
        setTitle("口味做法");
        mTvName = get(R.id.tv_choose_name);
        mTvDiscountPrice = get(R.id.tv_choose_discount_price);
        mTvDishPrice = get(R.id.tv_choose_price);
        mIvPic = get(R.id.iv_choose_pic);
        mItemTaste = get(R.id.item_choose_taste);
        mItemMakeUp = get(R.id.item_choose_makeup);

    }

    public void setChooseData(SupplementModel datas) {
        if (datas == null) {
            return;
        }
        SupplementModel data = datas;
        if (data.taste != null) {//有口味这个属性
            mItemTaste.setVisibility(View.VISIBLE);
            mItemTaste.setData(data.taste);
            mItemTaste.setChooseAddName(CodeUtils.getIdString(R.string.string_taste));
            LogUtils.dNormal(TAG, "setChooseData: 口味" + data.taste.toString());
        } else {
            mItemTaste.setVisibility(View.GONE);
        }

        if (data.makeup != null) {//有做法这个属性
            mItemMakeUp.setVisibility(View.VISIBLE);
            mItemMakeUp.setMakeUpData(data.makeup);
            mItemMakeUp.setChooseAddName(CodeUtils.getIdString(R.string.string_makeUp));
            LogUtils.dNormal(TAG, "setChooseData: 做法" + data.taste.toString());
        } else {
            mItemMakeUp.setVisibility(View.GONE);
        }
    }

    /**
     * 设置上面菜品的数据
     */
    public void setDishData(DishModel dishData) {
        if (dishData == null) {
            return;
        }
        if (!TextUtils.isEmpty(dishData.dish_name)) {
            mTvName.setText(dishData.dish_name);
        }
        mTvDiscountPrice.setText("￥" + dishData.dish_discount_price + "/" + dishData.dish_unit);
        mTvDishPrice.setData("￥" + dishData.dish_price + "/" + dishData.dish_unit);
        GlideUtil.getInstance().loadDefaultImage(getActivity(), dishData.dish_pic, mIvPic);
    }

    /**
     * 获取选择的口味
     *
     * @return 0：证明没有做法这个选项  ""： 证明没有选择
     */
    public String getChooseTaste() {
        if (mItemTaste.getVisibility() == View.VISIBLE) {//有口味这个选项
            if (mItemTaste.getSelectTaste() != null) {//选择了口味
                return mItemTaste.getSelectTaste().taste_name;
            } else {//没选择口味
                ToastUtils.showToast(CodeUtils.getIdString(R.string.string_hintChooseTaste));
                return "";
            }
        }
        return "0";
    }

    /**
     * 获取选择的做法
     *
     * @return 0：证明没有做法这个选项  ""： 证明没有选择
     */
    public String getChooseMakeUp() {
        if (mItemMakeUp.getVisibility() == View.VISIBLE) {//有口味这个选项
            if (mItemMakeUp.getSelectMakeUp() != null) {//选择了口味
                return mItemMakeUp.getSelectMakeUp().practice_name;
            } else {//没选择口味
                ToastUtils.showToast(CodeUtils.getIdString(R.string.string_hintChooseMakeUp));
                return "";
            }
        }
        return "0";
    }
}
